﻿using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Controllers;
using Batman.Jianbei.Forum.Areas.Forum.Filters;
using Batman.Jianbei.Forum.Core.Domains.Posts;
using Batman.Jianbei.Forum.Services;
using Batman.Jianbei.Forum.Services.Posts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Batman.Jianbei.Forum.Areas.Forum
{
    [Area("Forum")]
    [Authorize]
    public class PostController : AbpController
    {
        public CommentService CommentService { get; set; }

        public PostService PostService { get; set; }

        /// <summary>
        /// 获取评论分页列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="postId"></param>
        /// <returns></returns>
        public IActionResult Comments(PagedResultRequestDto page, CommentFilter filter)
        {
            var result = CommentService.GetComments(page, filter);

            return Json(result);
        }

        /// <summary>
        /// 我的点赞列表
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task<IActionResult> ILike(PagedResultRequestDto page)
        {
            var result = await PostService.GetMyTintPostAsync(page, User.GetWxUserId(), PostTintType.Like);
            return Json(result);
        }

        /// <summary>
        /// 我的收藏 
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task<IActionResult> IFavorite(PagedResultRequestDto page)
        {
            var result = await PostService.GetMyTintPostAsync(page, User.GetWxUserId(), PostTintType.Favorite);
            return Json(result);
        }

        /// <summary>
        /// 获取我的文章
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task<IActionResult> MyPost(PagedResultRequestDto page)
        {
            var filter = new PostFilter();
            filter.CreateBy = User.GetWxUserId();
            filter.DisplayAccess = true;
            var result = await PostService.GetPostAsync(page, filter, User.GetWxUserId());

            return Json(result);
        }

        /// <summary>
        /// 由作者删除帖子
        /// </summary>
        /// <param name="postId"></param>
        /// <returns></returns>
        public IActionResult TrashPost(string postId)
        {
            var result = PostService.TrashPostByOwnerAsync(postId, User.GetWxUserId());
            return Json(result);
        }
    }
}